package com.ls.component;

import com.ls.utils.AesUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @FileName AesComponent
 * @Description AES加密解密
 * @Author shengbinhe
 * @Date 2019/10/2 14:21
 * @Version 1.0
 **/
@Component
public class AesComponent {

    @Value("${AES.aesKey}")
    private String aesKey;

    public String getAesKey() {
        return aesKey;
    }

    public void setAesKey(String aesKey) {
        this.aesKey = aesKey;
    }

    /**
     * AES加密
     *
     * @param word
     * @return
     */
    public String encrypt(String word) {
        String encrypt = null;
        try {
            encrypt = AesUtil.encrypt(word, aesKey);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return encrypt;
    }

    /**
     * AES解密
     *
     * @param word
     * @return
     */
    public String decrypt(String word) {
        String decrypt = null;
        try {
            decrypt = AesUtil.decrypt(word, aesKey);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return decrypt;
    }

    public  static void  main(String[] args){
        AesComponent aes = new AesComponent();
        aes.setAesKey("7418529633214567");

        String str1 = "72ce87f8e0077e8f920583c55afb9fe2";
        String str2 = "914854ec20c228722808e61f0caa2a20d7a7cdbae2a9d7463d7db097f5f76ccc";

        System.out.println(aes.decrypt(str1));
        System.out.println(aes.decrypt(str2));

        String str3 = "29d60f3b5cba1a20c88499041daca924";
        String str4 = "8e6d7a595a1438e219022557b493f84f2833b7328aaab3fc5f2168763bd5da31";

        System.out.println(aes.decrypt(str3));
        System.out.println(aes.decrypt(str4));


    }
}
